<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Admin\AdminCateController;

class HomepageController extends Controller
{
    public function index()
    {   
    	$res = (new AdminCateController)->getCateByMessage(0);

        foreach($res as $k => $v) {

            foreach($v->cate as $k =>$v ) {

              $v->cate = DB::table('project_goods')->where('tid',$v->id)->get();
          
            }

            $arr[] = $v;
        }

    	
    	$row = DB::table("project_webconf")->where('id',1)->first()->status;
       
        if($row == 1) {

            return view('home/home',['res'=>$res]);
        } else {

            return redirect("/Home/error");
        }

        
    }
    /**
    *	首页搜索
    */
    public function find(Request $request)	
    {	
    	//获取搜索的值
    	$a = $request->only('p');
    	//模糊的搜索
    	$res = DB::table('project_goods') 
    	->where('goodsname','like','%'.$request->input('q').'%')
        ->paginate(5);
    	//var_dump($res);die;
    	
    	return view('/home/search',['row'=>$res]);
    }		
}
